// Ionic Starter App

// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
// 'starter.controllers' is found in controllers.js
angular.module('ionicApp', ['ionic', 'ionicApp.controllers'])

	.run(function($ionicPlatform) {
		$ionicPlatform.ready(function() {
			// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
			// for form inputs)
			if(window.cordova && window.cordova.plugins.Keyboard) {
				cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
			}
			if(window.StatusBar) {
				// org.apache.cordova.statusbar required
				StatusBar.styleDefault();
			}
		});
	})

	.config(function($stateProvider, $urlRouterProvider) {

		$stateProvider
			.state('signin', {
				url: "/sign-in",
				templateUrl: "sign-in.html",
				controller: 'SignInCtrl'
			})
			.state('forgotpassword', {
				url: "/forgot-password",
				templateUrl: "forgot-password.html"
			})
			.state('app', {
				url: "/app",
				abstract: true,
				templateUrl: "menu.html",
				controller: 'MenuCtrl'
			})
			.state('app.home', {
				url: "/home",
				views: {
					'menuContent': {
						templateUrl: "home.html",
						controller: 'HomeCtrl'
					}
				}
			})
			.state('app.business_manage', {
				url: "/business_manage",
				views: {
					'menuContent' :{
						templateUrl: "business_manage.html",
						controller: 'BusinessManageCtrl'
					}
				}
			})
			.state('app.preferential_list', {
				url: "/preferential_list",
				views: {
					'menuContent' :{
						templateUrl: "preferential_list.html",
						controller: 'PreferentialListCtrl'
					}
				}
			})
			.state('app.search_list', {
				url: "/search_list/:business_category_id",
				views: {
					'menuContent' :{
						templateUrl: "search_list.html",
						controller: 'SearchListCtrl'
					}
				}
			})

			.state('app.add_merchant', {
				url: "/add_merchant",
				views: {
					'menuContent' :{
						templateUrl: "add_merchant.html",
						controller: 'AddMerchantCtrl'
					}
				}
			})

			.state('app.add_merchant_next', {
				url: "/add_merchant_next/:view_title/:business_id",
				views: {
					'menuContent' :{
						templateUrl: "add_merchant_next.html",
						controller: 'AddMerchantNextCtrl'
					}
				}
			})

			.state('app.add_merchant_success', {
				url: "/add_merchant_success/:id",
				views: {
					'menuContent' :{
						templateUrl: "add_merchant_success.html",
						controller: 'AddMerchantSuccessCtrl'
					}
				}
			})

			.state('app.merchant_view', {
				url: "/merchant_view/:id",
				views: {
					'menuContent' :{
						templateUrl: "merchant_view.html",
						controller: 'MerchantViewCtrl'
//						params:['view_title','business_id']
					}
				}
			})

			.state('app.add_workman', {
				url: "/add_workman/:business_id",
				views: {
					'menuContent' :{
						templateUrl: "add_workman.html",
						controller: 'AddWorkmanCtrl'
					}
				}
			})

			.state('app.preferential_audit_view', {
				url: "/preferential_audit_view/:id",
				views: {
					'menuContent' :{
						templateUrl: "preferential_audit_view.html",
						controller: 'PreferentialAuditViewCtrl'
					}
				}
			})

			.state('app.preferential_view', {
				url: "/preferential_view/:id",
				views: {
					'menuContent' :{
						templateUrl: "preferential_view.html",
						controller: 'PreferentialViewCtrl'
					}
				}
			})

			.state('app.my_set', {
				url: "/my_set",
				views: {
					'menuContent': {
						templateUrl: "my_set.html",
						controller:'MySetCtrl'
					}
				}
			})

			.state('app.feedback', {
				url: "/feedback",
				views: {
					'menuContent': {
						templateUrl: "feedback.html",
						controller:'FeedbackCtrl'
					}
				}
			})

			.state('app.change_password', {
				url: "/change_password",
				views: {
					'menuContent': {
						templateUrl: "change_password.html",
						controller:'ChangePasswordCtrl'
					}
				}
			})

			//物业首页
			.state('app.property', {
				url: "/property",
				views: {
					'menuContent': {
						templateUrl: "property.html",
						controller:'PropertyCtrl'
					}
				}
			})
			//居委会首页
			.state('app.committee', {
				url: "/committee",
				views: {
					'menuContent': {
						templateUrl: "committee.html",
						controller:'CommitteeCtrl'
					}
				}
			})
			//物业，居委会简介
			.state('app.property_intro', {
				url: "/property_intro",
				views: {
					'menuContent': {
						templateUrl: "property_intro.html",
						controller:'PropertyIntroCtrl'
					}
				}
			})
			//物业，居委会简介编辑
			.state('app.property_intro_edit', {
				url: "/property_intro_edit",
				views: {
					'menuContent': {
						templateUrl: "property_intro_edit.html",
						controller:'PropertyIntroEditCtrl'
					}
				}
			})
			//物业，居委会公告
			.state('app.property_notice', {
				url: "/property_notice",
				views: {
					'menuContent': {
						templateUrl: "property_notice.html",
						controller:'PropertyNoticeCtrl'
					}
				}
			})
			//物业，居委会发布公告
			.state('app.property_notice_post', {
				url: "/property_notice_post",
				views: {
					'menuContent': {
						templateUrl: "property_notice_post.html",
						controller:'PropertyNoticePostCtrl'
					}
				}
			})
			//物业，居委会编辑公告
			.state('app.property_notice_edit', {
				url: "/property_notice_edit/:id",
				views: {
					'menuContent': {
						templateUrl: "property_notice_edit.html",
						controller:'PropertyNoticeEditCtrl'
					}
				}
			})
			//物业，居委会资讯
			.state('app.property_news', {
				url: "/property_news",
				views: {
					'menuContent': {
						templateUrl: "property_news.html",
						controller:'PropertyNewsCtrl'
					}
				}
			})
			//物业，居委会公告详情
			.state('app.property_notice_view', {
				url: "/property_notice_view/:id",
				views: {
					'menuContent': {
						templateUrl: "property_notice_view.html",
						controller:'PropertyNoticeViewCtrl'
					}
				}
			})
			//物业，居委会资讯详情
			.state('app.property_new_view', {
				url: "/property_new_view/:id",
				views: {
					'menuContent': {
						templateUrl: "property_new_view.html",
						controller:'PropertyNewViewCtrl'
					}
				}
			})

			//物业，居委会资讯添加
			.state('app.property_news_add', {
				url: "/property_news_add/:id",
				views: {
					'menuContent': {
						templateUrl: "property_news_add.html",
						controller:'PropertyNewAddCtrl'
					}
				}
			})
			//物业，居委会资讯编辑
			.state('app.property_news_edit', {
				url: "/property_news_edit/:id",
				views: {
					'menuContent': {
						templateUrl: "property_news_edit.html",
						controller:'PropertyNewEditCtrl'
					}
				}
			})

		;

// 社区代表6/居委会用户7/物业用户8
		if(storage.getItem('user_type')){
			if(storage.getItem('user_type') == 7) {
				$urlRouterProvider.otherwise("/app/committee");
			}else if(storage.getItem('user_type') == 8){
				$urlRouterProvider.otherwise("/app/property");
			}else{
				$urlRouterProvider.otherwise("/app/home");
			}
		}else{
			$urlRouterProvider.otherwise("/sign-in");
		}


	});

